//
//  DataBaseTool.m
//  LYYGame
//
//  Created by YUJIABO on 17/3/10.
//  Copyright © 2017年 YUJIABO. All rights reserved.
//

#import "DataBaseTool.h"
#import <FMDatabase.h>
#import "UserDao.h"
@interface DataBaseTool()

@end
@implementation DataBaseTool

- (void)dealloc
{
    self.dbQueue = nil;
}
- (FMDatabaseQueue*)dbQueue
{
    if (!_dbQueue) {
        _dbQueue = [FMDatabaseQueue databaseQueueWithPath:[self dbPath]];
    }
    
    return _dbQueue;
}

- (NSString *)dbPath{
    NSString *dbPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)lastObject]stringByAppendingPathComponent:@"Lyy.sqlite"];
      NSLog(@"数据库路径---%@",dbPath);
    return dbPath;
}
static DataBaseTool * instance = nil;
+ (instancetype)shareInstance
{
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
       
        instance = [[self alloc]init];
    });
    
    return instance;
}


- (BOOL) checkTableExist:(NSString *)tableName withFMData:(FMDatabase *)dbDatabase

{
    BOOL result;
    
    tableName = [tableName lowercaseString];
    
    FMResultSet *rs = [dbDatabase executeQuery:@"select [sql] from sqlite_master where [type] = 'table' and lower(name) = ?", tableName];
    
    result = [rs next];
    
    [rs close];
    
    return result;
    
}

- (void)createDataBase
{
    [UserDao createUserInforTable];
}
@end
